import axios from 'axios'
import Cookies from 'js-cookie'



axios.defaults.baseURL='http://127.0.0.1:8000/';
// axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
if (Cookies.get('token')) {  // 判断是否存在token，如果存在的话，则每个http header都加上token
  axios.defaults.headers.common['Authorization'] = `JWT ${Cookies.get('token')}`;
}


//评论文章
export const postComment= (parms) => {
  return new Promise((resolve, reject) => {
    axios.post('/api/comment/',parms).then(res=>{
      resolve(res)})
      .catch(error=>{reject(error)});
  })
};


//拉取评论
export const getComment= (id) => {
  return new Promise((resolve, reject) => {
    axios.get('/api/comment/?article=' + id).then(res=>{
      resolve(res)})
      .catch(error=>{reject(error)});
  })
};
